package com.whli.autumn.mall.web.controller.wms;

import com.github.pagehelper.PageInfo;
import com.whli.autumn.core.app.annotation.ApiVersion;
import com.whli.autumn.core.extend.controller.BaseController;
import com.whli.autumn.core.permission.annotation.RequirePermissions;
import com.whli.autumn.core.share.ResponseResult;
import com.whli.autumn.mall.web.controller.convert.wms.WarehouseInfoConvert;
import com.whli.autumn.mall.wms.domain.dto.warehouseinfo.*;
import com.whli.autumn.mall.wms.domain.entity.WarehouseInfo;
import com.whli.autumn.mall.wms.service.IWarehouseInfoService;
import com.whli.autumn.mall.wms.domain.vo.warehouseinfo.WarehouseInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>仓库信息API</p>
 *
 * @author whli
 * @version 1.0.0
 * @since 2023-04-09 08:37
 */
@Api(tags = "仓库管理-仓库信息")
@ApiVersion
@RestController
@RequestMapping(value = "/wms/warehouseInfo")
public class WarehouseInfoController extends BaseController<WarehouseInfo, IWarehouseInfoService> {

    /**
     * <p>查询仓库信息详情</p>
     *
     * @author whli
     * @since 2023-04-09 08:37
     * @param id 仓库信息主键
     * @return
     */
    @ApiOperation(value = "查询仓库信息", httpMethod = "GET")
    @ApiImplicitParam(value = "主键", name = "id", required = true)
    @RequirePermissions("wms:warehouse-info:view")
    @GetMapping
    public ResponseResult<WarehouseInfoVO> view(String id) {
        WarehouseInfo entity = service.getByPK(id);
        return ResponseResult.success(WarehouseInfoConvert.INSTANCE.domainToVO(entity));
    }

    /**
     * <p>分页查询仓库信息</p>
     *
     * @author  whli
     * @since   2023-04-09 08:37
     * @param   entity 分页参数
     * @return
     */
    @ApiOperation(value = "分页查询仓库信息", httpMethod = "GET")
    @RequirePermissions("wms:warehouse-info:list")
    @GetMapping("page")
    public ResponseResult<PageInfo<WarehouseInfoVO>> listByPage(WarehouseInfoPageDTO entity) {
        PageInfo<WarehouseInfoVO> page = service.listByPage(entity);
        return ResponseResult.success(page);
    }

    /**
     * <p>查询所有启用仓库信息</p>
     *
     * @author whli
     * @since 2023/4/15 15:01
     * @param entity
     * @return
     */
    @ApiOperation( value = "查询所有启用仓库信息", httpMethod = "GET")
    @RequirePermissions({"user"})
    @GetMapping({"list"})
    public ResponseResult<List<WarehouseInfoVO>> listAll(WarehouseInfoQueryDTO entity) {
        List<WarehouseInfoVO> list = service.listWarehouseInfo(entity);
        return ResponseResult.success(list);
    }

    /**
     * <p>新增仓库信息</p>
     *
     * @author  whli
     * @since   2023-04-09 08:37
     * @param   entity 新增参数
     * @return
     */
    @ApiOperation(value = "新增仓库信息", httpMethod = "POST", consumes = "application/json")
    @RequirePermissions("wms:warehouse-info:add")
    @PostMapping
    public ResponseResult<String> save(@RequestBody @Valid WarehouseInfoAddDTO entity) {
        String id = service.save(WarehouseInfoConvert.INSTANCE.addToDomain(entity));
        return !StringUtils.isEmpty(id) ? ResponseResult.success("新增仓库信息成功") : ResponseResult.fail("新增仓库信息失败");
    }

    /**
     * <p>修改仓库信息</p>
     *
     * @author  whli
     * @since   2023-04-09 08:37
     * @param   entity  修改参数
     * @return
     */
    @ApiOperation(value = "修改仓库信息", httpMethod = "PUT", consumes = "application/json")
    @RequirePermissions("wms:warehouse-info:update")
    @PutMapping
    public ResponseResult<String> update(@RequestBody @Valid WarehouseInfoUpdateDTO entity) {
        String id = service.update(WarehouseInfoConvert.INSTANCE.updateToDomain(entity));
        return !StringUtils.isEmpty(id) ? ResponseResult.success("修改仓库信息成功") : ResponseResult.fail("修改仓库信息失败");
    }

    /**
     * <p>删除仓库信息</p>
     *
     * @author  whli
     * @since   2023-04-09 08:37
     * @param   ids 主键集合 java.util.List<String>
     * @return
     */
    @ApiOperation(value = "删除仓库信息", httpMethod = "DELETE")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "主键集合", name = "ids", required = true)
    })
    @RequirePermissions("wms:warehouse-info:delete")
    @DeleteMapping
    public ResponseResult<String> delete(@RequestBody List<String> ids) {
        boolean flag = service.deleteBatch(ids);
        return flag ? ResponseResult.success("删除仓库信息成功") : ResponseResult.fail("删除仓库信息失败");
    }

    /**
     * <p>启用仓库信息</p>
     *
     * @author whli
     * @since 2023/4/29 14:36
     * @param entity
     * @return
     */
    @ApiOperation(value = "启用仓库信息", httpMethod = "PUT")
    @RequirePermissions({"wms:warehouse-info:enable"})
    @PutMapping({"enable"})
    public ResponseResult<String> enable(@RequestBody @Valid WarehouseInfoStatusDTO entity) {
        boolean flag = service.enable(entity.getId());
        return flag ? ResponseResult.success("启用仓库成功") : ResponseResult.fail("启用仓库失败");
    }

    /**
     * <p>禁用仓库信息</p>
     *
     * @author whli
     * @since 2023/4/29 14:36
     * @param entity
     * @return
     */
    @ApiOperation(value = "禁用仓库信息", httpMethod = "PUT")
    @RequirePermissions({"wms:warehouse-info:disable"})
    @PutMapping({"disable"})
    public ResponseResult<String> disable(@RequestBody @Valid WarehouseInfoStatusDTO entity) {
        boolean flag = service.disable(entity.getId());
        return flag ? ResponseResult.success("禁用仓库成功") : ResponseResult.fail("禁用仓库失败");
    }

}
